<style type="text/css">
    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="内部编号" prop="dormcode">
            <i-input v-model="formValidate.dormcode" placeholder="请输入内部编号"></i-input>
        </Form-item>
        <Form-item label="位置" prop="location">
            <i-input v-model="formValidate.location" placeholder="请输入位置"></i-input>
        </Form-item>
        <Form-item label="入住人数" prop="peoplecount">
            <i-input v-model="formValidate.peoplecount" placeholder="请输入入住人数"></i-input>
        </Form-item>
        <Form-item label="营房使用性别" prop="sextype">
            <i-select v-model="formValidate.sextype" placeholder="请选择营房使用性别">
                <i-option value="男">男</i-option>
                <i-option value="女">女</i-option>
            </i-select>
        </Form-item>
        <Form-item label="营房类型" prop="dormtype">
            <i-select v-model="formValidate.dormtype" placeholder="请选择营房类型">
                <i-option value="住宿">住宿</i-option>
                <i-option value="办公">办公</i-option>
                <i-option value="其它用途">其它用途</i-option>
            </i-select>
        </Form-item>
        <Form-item label="房间简述" prop="comment">
            <Input v-model="formValidate.comment" type="textarea" :autosize="{minRows: 2,maxRows: 5}"
                   placeholder="请输入..."></Input>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    dormcode: '',
                    location: '',
                    peoplecount: "",
                    dormtype: '',
                    sextype: '',
                    comment: '',
                },
                ruleValidate: {
                    dormcode: [
                        {required: true, message: '营房内部编号不能为空', trigger: 'blur'}
                    ],
                    location: [
                        {required: true, message: '营房所在位置不能为空', trigger: 'blur'}
                    ],
                    peoplecount: [
                        {required: true, message: '请填写营房标准入住人数', trigger: 'blur'}
                    ],
                    dormtype: [
                        {required: true, message: '请选择营房类型', trigger: 'change'}
                    ],
                    sextype: [
                        {required: true, message: '请选择营房使用性别', trigger: 'change'}
                    ],
                },
            }
        },
        mounted: function () {
            let id = this.$route.query.id;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    curPage: this.$route.query.curPage,
                    pageSize: 10,
                };

                apiUtil.get(that, apiUtil.urls.ListDorms, para, function (res) {
                    that.$Loading.finish();
                    let data = res.Msg.Arrays[that.$route.query.curPage];

                    that.formValidate.sextype = data.sextype;
                    that.formValidate.dormtype = data.dormtype;
                    that.formValidate.peoplecount = data.peoplecount.toString();
                    that.formValidate.location = data.location;
                    that.formValidate.dormcode = data.dormcode;
                    that.formValidate.comment = data.comment;


                    // that.formValidate.state =res.data.state.toString();
                });
            },
            //修改
            updateData: function (model) {
                let that = this;


                model.id =this.$route.query.id;
                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditDormInfo, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
